package java8stream;

import java.io.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by ZhuQianli on 2018/1/16.
 */
public class StreamLimitSkipFlatMapDistinct {
    public static void main(String[] args) throws IOException {

        List<Person> list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            list.add(new Person("name" + i, i * 10));
        }

        List<String> collect = list.stream().map(Person::getName).limit(13).skip(3).collect(Collectors.toList());
        System.out.println(collect);

        List<Integer> collect1 = list.stream().map(Person::getAge).limit(20).sorted((a, b) -> b - a).collect(Collectors.toList());
        System.out.println(collect1);

        BufferedReader reader = new BufferedReader(new FileReader("1.txt"));
        Integer maxLength = reader.lines().map(String::length).max(Comparator.comparingInt(c -> c)).get();
        reader.close();
        System.out.println(maxLength);

        BufferedReader reader2 = new BufferedReader(new FileReader("1.txt"));
        reader2.lines().flatMap(e -> Stream.of(e.split(" "))).map(e -> e.replaceAll("\\.|,|\"|\'", "").toUpperCase()).filter(e -> e.length() > 0).distinct().forEach(System.out::println);
        reader2.close();




    }

    static class Person {
        String name;
        Integer age;

        public Person(String name, Integer age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public Person setName(String name) {
            this.name = name;
            return this;
        }

        public Integer getAge() {
            return age;
        }

        public Person setAge(Integer age) {
            this.age = age;
            return this;
        }
    }

}
